<?php
/**
 * Created by PhpStorm.
 * User: 海峡
 * Date: 2021/1/11
 * Time: 13:42
 */
include __DIR__.'/function.php';
$url = 'https://news.ke.com/cs/baike/0033/';
$html = http_request($url);
//正则表达式匹配出title

//修饰符
//i 不区分大小写  U禁止贪婪  s剧烈换行
//$preg = '/<title>(.*)<\/title>/iUs';
//$preg = '#<title>(.*)</title>#iUs';
////
////preg_match_all($preg,$html,$arr);
////
////print_r($arr);
///
//申明一个dom对象
$dom = new DOMDocument();
//忽略html不严格的格式
libxml_use_internal_errors(1);
$dom->loadHTML($html);
//转为xpath对象
$xpath = new DOMXpath($dom);
//查询路径
//$query = '/html/head/title';
//$nodeList = $xpath->query($query);
//foreach ($nodeList as $item){
//    echo $item->nodeValue;
//}
//查询所有图片
$query = '//img/@data-original';
$nodeList = $xpath->query($query);
foreach ($nodeList as $item){
    echo $item->nodeValue."\n";
}